IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='simDB')
CREATE DATABASE simDB

USE simDB

GO
/*************************************************************************************************
	Table tNhaMang
	Name: tNhaMang
	Purpose: Contain the information of mobile supplier
*************************************************************************************************/
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name='tNhaMang')
CREATE TABLE tNhaMang
(
	[MID]			INT NOT NULL IDENTITY,
	[TenNhaMang]	NVARCHAR(50) NOT NULL,
	[LogoPath]		NVARCHAR(200)	
	CONSTRAINT pk_tNhaMang_MID PRIMARY KEY (MID)	
	
)

GO
/*************************************************************************************************
	Table tLoaiSim
	Name: tLoaiSim
	Purpose: Contain the information of sim type
*************************************************************************************************/
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name='tLoaiSim')
CREATE TABLE tLoaiSim
(
	[TID]			INT NOT NULL IDENTITY,
	[TenLoai]		NVARCHAR(100) NOT NULL,
	
	CONSTRAINT pk_tLoaiSim_TID PRIMARY KEY (TID)	
	
)

GO
/*************************************************************************************************
	Table tSim
	Name: tgPerson
	Purpose: Contain the information of sim
*************************************************************************************************/
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name='tSim')
CREATE TABLE tSim
(
	[SID]			INT NOT NULL IDENTITY,
	[SoSim]			VARCHAR(50) NOT NULL,
	[Gia]			DECIMAL,
	[MID]			INT,
	[TID]			INT

	CONSTRAINT pk_tSim_SID PRIMARY KEY (SID)	

	CONSTRAINT fk_tSim_tNhaMang_MID FOREIGN KEY (MID) REFERENCES tNhaMang(MID),  

	CONSTRAINT fk_tSim_tLoaiSim_TID FOREIGN KEY (TID) REFERENCES tLoaiSim(TID)  
)

/*************************************************************************************************
	Table tUser
	Name: tUser
	Purpose: Contain the information of users
*************************************************************************************************/
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name='tUser')
CREATE TABLE tUser
(
	[UID]			VARCHAR (10) NOT NULL,
	[Hash]			NVARCHAR(50) NOT NULL,
	[Tel]			NVARCHAR(50)

	CONSTRAINT pk_tUser_UID PRIMARY KEY (UID)	
	
)

/*************************************************************************************************
	Table tYahooContact
	Name: tYahooContact
	Purpose: Contain the information of yahoo nicks
*************************************************************************************************/
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name='tYahooContact')
CREATE TABLE tYahooContact
(
	[YID]			VARCHAR (50) NOT NULL,
	[Tel]			NVARCHAR(50)

	CONSTRAINT pk_tYahooContact_YID PRIMARY KEY (YID)	
	
)

-- drop table tSim

